#include <iostream>

#include "University.h"
#include "Student_t.h"
#include <list>
University& uv = University::getObj();
vector <Student_t*> students;

void addStudent() {
	int x;
	bool cont = true;
	while (cont) {
		cout << endl << " Which faculty will the student belong to? " 	<< endl
				 << "	0: Exact Science Faculty " 				<< endl
				 << "	1: Faculty of Humanities " 			<< endl
				 << "	9: Cancel "				<< endl << endl;

		while (cout << "Enter your choice : " && !(cin >> x)) {
				cin.sync();
				cin.clear();
				cout << "Invalid input; please re-enter.\n";
		}

		switch (x) {
		case 0: { long id;
				cout << "Student ID: ";
				cin >> id;
				students.push_back(new Student_t(&uv,"ESF",id));
				cout << "Student " << id << " added to ESF" << endl;
				cont = false;
				break;}
		case 1: { long id;
				cout << "Student ID: ";
				cin >> id;
				students.push_back(new Student_t(&uv,"FOH",id));
				cont = false;
				cout << "Student " << id << " added to FOH" << endl;
				break;}
		case 9: { cont = false; break; }
		default: break;
		}
	}
}

void Menu() {
	int x;
	bool cont = true;
	cout << endl << " University Management System " << endl
				 << " ---------------------------- " << endl << endl;

	while (cont) {
		cout << endl << " What would you like to do? " 	<< endl
				 << "	0: Add Student " 				<< endl
				 << "	1: Change the price " 			<< endl
				 << "	2: Cancel tomorrow's lecture "	<< endl
				 << "	3: Tell about students"			<< endl
				 << "	9: Exit "				<< endl << endl;

		while (cout << "Enter your choice : " && !(cin >> x)) {
				cin.sync();
				cin.clear();
				cout << "Invalid input; please re-enter.\n";
		}

		switch(x) {
			case 0: { addStudent(); break; }
			case 1: { 
					double price;
					cout << "New Price : ";
					cin >> price;
					uv.changePrice(price); 
					cout << "Price changed!" << endl;
					break; 
					}
			case 2: { 
					string name;
					cin.sync();
					cout << "Lecture Name : ";
					getline(cin,name,'\n');
					uv.cancelLecture(name);
					cout << "Lecture cancelled!" << endl;
					break;	}
			case 3: {
					for (int i = 0; i < students.size(); i++) 
						students[i]->tell();
					break;
					}
			case 9: cont = false;
			default: break;
		}
	}

	return;
}


int main() {
	
	Menu(); //Interact with user
	
	//interaction complete - user exited

	for (vector<Student_t *>::iterator it = students.begin(); it != students.end(); it++) 
		delete (*it);
	students.clear();
	
	return 0;
	
}